package edu.eas.admin.component;

import edu.eas.admin.service.MenuService;
import edu.eas.common.api.ResultCode;
import edu.eas.common.exception.ApiException;
import edu.eas.common.exception.GlobalExceptionHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 资源与角色访问对应关系操作组件
 *
 * @author cql
 */
@Component
public class ResourceRoleRulesHolder {

    private static final Logger LOGGER = LoggerFactory.getLogger(ResourceRoleRulesHolder.class);


    @Autowired
    private MenuService menuService;

    @PostConstruct
    public void initResourceRolesMap() {
        try {
            menuService.initMenuRolesMap();
        } catch (Exception e) {
            // 防止出现异常导致程序没有启动
            LOGGER.error("错误原因:'{}'", e.getCause());
            throw new ApiException(ResultCode.FAILED);
        }
    }

}
